/*jslint maxerr: 50, indent: 4, browser: true */
/*global define */

(function () {
    "use strict";

    define("array.join", ["mergeModules", "init", "array.length"], function (make) {
        var buri = make.mergeModules(arguments),
            config = {
                "compatability": {}
            },
            func = [].constructor.prototype.join,
            join;

        if (!config.compatability.all && !config.compatability["array.push"] && typeof func === "function") {
            join = function (array, separator) {
                return func.call(array, separator);
            };
        } else {
            join = function (array, separator) {
                var last = buri.array.length(array) - 1,
                    i = 0,
                    string = "";

                while (i < last) {
                    string += array[i] + separator;
                    i += 1;
                }

                return string + array[i];
            };
        }

        join.init = function (options) {
            buri.init(config, options);
            buri.array.length(config);
        };

        return {
            "array": {
                "join": join
            }
        };
    });
}());
